package a51qindian.com.comprehensive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.li.interfaces.OnItemClickListener;
import com.li.utils.TransformUtil;
import com.li.widget.DoubleTextView;

import java.util.List;

import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.fragment.WithdrawVerifyFragment;
import a51qindian.com.comprehensive.model.WithDrawInfo;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/9/21 0021
 * Description: 提现申请适配器
 */

public class WithdrawVerifyAdapter extends RecyclerView.Adapter<WithdrawVerifyAdapter.WithdrawVerifyHolder> {


    private String mVerifyState;
    private LayoutInflater mInflater;

    public void setWithDrawInfoList(List<WithDrawInfo> withDrawInfoList) {
        mWithDrawInfoList = withDrawInfoList;
        notifyDataSetChanged();
    }

    private List<WithDrawInfo> mWithDrawInfoList;

    public void setItemClickListener(OnItemClickListener itemClickListener) {
        mItemClickListener = itemClickListener;
    }

    private OnItemClickListener mItemClickListener;

    public WithdrawVerifyAdapter(Context context, String verifyState) {
        mInflater = LayoutInflater.from(context);
        mVerifyState = verifyState;
    }

    @Override
    public WithdrawVerifyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_withdraw_verify, parent, false);
        final WithdrawVerifyHolder holder = new WithdrawVerifyHolder(view);
        if (mVerifyState.equals(WithdrawVerifyFragment.VERIFY_UNFINISHED)) {
            holder.mBtnDeal.setVisibility(View.VISIBLE);
            if (mItemClickListener != null) {
                holder.mBtnDeal.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mItemClickListener.onItemClick(v, holder.getLayoutPosition());
                    }
                });
            }
        } else {
            holder.mBtnDeal.setVisibility(View.GONE);
        }
        return holder;
    }

    @Override
    public void onBindViewHolder(WithdrawVerifyHolder holder, int position) {
        WithDrawInfo withDrawInfo = mWithDrawInfoList.get(position);
        holder.mTxtShopName.setTxtRight(withDrawInfo.getShop_name());
        holder.mTxtManName.setTxtRight(withDrawInfo.getAccount_name());
        holder.mTxtMoney.setTxtRight(withDrawInfo.getMoney());
        holder.mTxtPhone.setTxtRight(withDrawInfo.getMobile());
        holder.mTxtType.setTxtRight(withDrawInfo.getBank_name());
        holder.mTxtAccount.setTxtRight(withDrawInfo.getAccount_name());
        holder.mTxtTime.setTxtRight(
                TransformUtil.timeFormat(withDrawInfo.getAdd_time()));
        String status = "";
        switch (withDrawInfo.getStatus()) {
            case "0":
                status = "未处理";
                break;
            case "1":
                status = "已通过";

                break;
            case "2":
                status = "已拒绝";
                break;
        }
        holder.mTxtStatus.setTxtRight(status);
    }

    @Override
    public int getItemCount() {
        return mWithDrawInfoList == null ? 0 : mWithDrawInfoList.size();
    }

    static class WithdrawVerifyHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.txt_shop_name)
        DoubleTextView mTxtShopName;
        @BindView(R.id.txt_man_name)
        DoubleTextView mTxtManName;
        @BindView(R.id.txt_money)
        DoubleTextView mTxtMoney;
        @BindView(R.id.txt_phone)
        DoubleTextView mTxtPhone;
        @BindView(R.id.txt_type)
        DoubleTextView mTxtType;
        @BindView(R.id.txt_account)
        DoubleTextView mTxtAccount;
        @BindView(R.id.txt_time)
        DoubleTextView mTxtTime;
        @BindView(R.id.btn_deal)
        Button mBtnDeal;
        @BindView(R.id.txt_status)
        DoubleTextView mTxtStatus;

        public WithdrawVerifyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
